package edu.mbb.ioc;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

/**
 * bean 工厂
 * 
 * @author mbb
 *
 */
public class BeanFactory {
	private static final Map<String, Object> IOC = new HashMap<>();

	/**
	 * 得到 ioc 容器
	 * 
	 * @return
	 */
	public static Map<String, Object> getIOC() {
		return IOC;
	}

	//
	public static Object getBean(String beanName) {
		return IOC.get(beanName);
	}

	public static void doInstance() {
		Set<Class<?>> classSet = ClassNames.getClassSet();
		if (classSet.isEmpty()) {
			return;
		}
		for (Class<?> clazz : classSet) {
			try {
				Object instance = clazz.newInstance();
				IOC.put(clazz.getName(), instance);
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
	}
}
